/**
 * 
 */
package jmine.tec.subscription.replicator;

import java.io.Serializable;

import jmine.tec.subscription.Publication;
import jmine.tec.subscription.Publisher;
import jmine.tec.subscription.PublisherManager;
import jmine.tec.subscription.SubscriptionSettings;
import jmine.tec.subscription.impl.PartialPublication;
import jmine.tec.subscription.impl.SubscriptionManagerImplementor;

/**
 * * Implementacao de {@link AbstractPublicationWrapper} que lida com {@link PartialPublication}
 * 
 * @author takeshi
 */
public class PartialPublicationWrapper extends AbstractPublicationWrapper implements Serializable {

    private static final long serialVersionUID = -5655084591922043422L;

    private final PartialPublication<Publication> partialPublication;

    /**
     * C'tor
     * 
     * @param settings {@link SubscriptionSettings}
     * @param publisherIdentification {@link String}
     * @param partialPublication {@link PartialPublication}
     */
    public PartialPublicationWrapper(SubscriptionSettings settings, String publisherIdentification,
            PartialPublication<Publication> partialPublication) {
        super(settings, publisherIdentification);
        this.partialPublication = partialPublication;
    }

    /**
     * {@inheritDoc}
     */
    @SuppressWarnings("unchecked")
    @Override
    public void handleLocally(SubscriptionManagerImplementor implementor, PublisherManager publisherManager) {
        Publisher<Publication> publisher = (Publisher<Publication>) publisherManager.getPublisher(this.getPublisherIdentification());
        if (publisher != null) {
            implementor.localPublishPartialPublication(publisher, this.getSettings(), this.partialPublication);
        }
    }

    /**
     * {@inheritDoc}
     */
    @SuppressWarnings("unchecked")
    @Override
    public void broadcast(SubscriptionManagerImplementor implementor, PublisherManager publisherManager) {
        Publisher<Publication> publisher = (Publisher<Publication>) publisherManager.getPublisher(this.getPublisherIdentification());
        if (publisher != null) {
            implementor.broadcastPartialPublication(publisher, this.getSettings(), this.partialPublication);
        }
    }
}